package cn.getech.data.metadata.controller.setting;

import cn.getech.data.intelligence.common.utils.R;
import cn.getech.data.metadata.model.req.setting.CollectionSettingReq;
import cn.getech.data.metadata.service.CollectionSettingService;
import cn.getech.system.center.annotation.SysLog;
import cn.getech.system.center.constant.OperationModulesEnum;
import cn.getech.system.center.constant.OperationTypeEnum;
import cn.getech.system.center.constant.module.ModuleEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @description: 元数据相关设置类
 * @author: wangzhaowen：kiss
 * @create: 2020/9/30 11:00
 * @version: 2020/9/30
 **/
@Slf4j
@Api(value="元数据相关设置类",tags={"元数据相关设置类"})
@RestController
@RequestMapping("md/setting")
public class CollectionSettingController {
    @Autowired
    private CollectionSettingService collectionSettingService;

    @ApiOperation("设置保存")
    @PostMapping("/save")  // /data-metadata/md/setting/save
    @SysLog(value="日志详情",type= OperationTypeEnum.UPDATECODE,
            modulesType = OperationModulesEnum.DATAMETADATACODE,platformModuleType = ModuleEnum.METADATA_GATHER_MODULE_CODE)
    public R save(@RequestBody CollectionSettingReq req){
        String res = collectionSettingService.save(req);
        if (StringUtils.isNotEmpty(res)) {
            return R.error(res);
        }
        return R.ok();
    }

    @ApiOperation("设置信息")
    @GetMapping("/info") // /data-metadata/md/setting/info
    public R  info() {
        CollectionSettingReq info = collectionSettingService.info();
        return R.okWithData(info);
    }
}
